package com.example.demo.rabbitMq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;

/**/
public class RabbitMqUtils {
    @Value("${spring.rabbitmq.host}")
    private static String host;
    @Value("${spring.rabbitmq.iotVirtual}")
    private static String virtualHost;
    @Value("${spring.rabbitmq.username}")
    private static String username;
    @Value("${spring.rabbitmq.password}")
    private static String password;
    @Value("${spring.rabbitmq.port}")
    private static int port;


    public static Channel getChannel() throws Exception{
        //创建工厂
        ConnectionFactory factory = new ConnectionFactory();
        //服务地址
        factory.setHost(host);
        //虚拟机
        factory.setVirtualHost(virtualHost);
        //账号
        factory.setUsername(username);
        //密码
        factory.setPassword(password);
        //端口
        factory.setPort(port);
        //创建连接
        Connection connection = factory.newConnection();
        //创建信道
        Channel channel = connection.createChannel();

        return channel;
    }


}
